package com.example.yls.demoa;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;

public class addStu extends AppCompatActivity {
private RadioButton
        radioButton1,
        radioButton2,
        radioButton3,
        radioButton4,
        radioButton5;
private Button add_picture;
private EditText edtName,edtAge;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_stu);
            radioButton1=findViewById(R.id.radiobtn1);
        radioButton2=findViewById(R.id.radiobtn2);
        radioButton3=findViewById(R.id.radiobtn3);
        radioButton4=findViewById(R.id.radiobtn4);
        radioButton5=findViewById(R.id.radiobtn5);
       add_picture=findViewById(R.id.add_picture);
       edtName=findViewById(R.id.edtName);
       edtAge=findViewById(R.id.edtAge);

          add_picture.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                String name=edtName.getText().toString();
                int age=Integer.parseInt(edtAge.getText().toString());
                int imgid=R.drawable.dog1;
                if(radioButton1.isChecked()){
                    imgid=R.drawable.dog1;
                }
                  else if(radioButton2.isChecked()){
                      imgid=R.drawable.dog2;
                  }
                else if(radioButton3.isChecked()){
                    imgid=R.drawable.dog3;
                }
                else if(radioButton4.isChecked()){
                    imgid=R.drawable.dog4;
                }
                else if(radioButton5.isChecked()){
                    imgid=R.drawable.dog5;
                }

                  Intent intent=new Intent();
                  intent.putExtra("NAME", name);
                  intent.putExtra("AGE", age);
                  intent.putExtra("IMG", imgid);
                  setResult(2001, intent);

                  finish();
              }
          });

    }
}
